package com.jiyun.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jiyun.mapper.AddManageMapper;
import com.jiyun.pojo.AddManage;
import com.jiyun.service.AddManageService;
import com.jiyun.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AddManageServiceImpl extends ServiceImpl<AddManageMapper, AddManage> implements AddManageService {

    @Autowired
    AddManageMapper addManageMapper;
    @Override
    public R findAddManage(AddManage addManage) {
        List<AddManage> list = addManageMapper.findAddManage(addManage);
        return R.ok().data("list",list);
    }

    @Override
    public R add(AddManage addManage) {
        if(addManage.getId()==null){
            addManage.setStatus(1);
            addManageMapper.insert(addManage);
        }else {
            addManageMapper.updateById(addManage);
        }

        return R.ok();
    }

    @Override
    public R findAddManageById(Integer id) {
        AddManage addManage = addManageMapper.selectById(id);
        return R.ok().data("addManage",addManage);
    }

    @Override
    public R deletemanage(Integer id) {
        addManageMapper.deleteById(id);
        return R.ok();
    }


    @Override
    public R updatestatus(Integer id) {
        AddManage addManage = addManageMapper.selectById(id);
        addManage.setStatus(0);
        addManageMapper.updateById(addManage);
        return R.ok();
    }

    @Override
    public R updatezt(Integer id) {
        AddManage addManage = addManageMapper.selectById(id);
        addManage.setStatus(1);
        addManageMapper.updateById(addManage);
        return R.ok();
    }

    @Override
    public R selectstatus() {
        AddManage addManage = addManageMapper.selectstatus();
        return R.ok().data("addManage",addManage);
    }
}
